package com.myph.model;

import com.myph.phctrl_t.NextActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;


public class Util {
	public static final String TAG = "DEBUG";  
    public static void sendMsg(int what,Handler handler){
        Message msg = new Message();
        msg.what = what;
        handler.sendMessage(msg);
    }
    public static void initInfo(Context context){
		
		Activity activity = (Activity)context;
		Intent intent = new Intent(context, NextActivity.class);
		
		if(!HttpUtil.isNetworkConnected(context)){
			Toast.makeText(context, "没有网络~", Toast.LENGTH_LONG).show();
		}
	
		context.startActivity(intent);
		
		activity.finish();
	}
	public static void myToast(Context context,String str){
	    Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
	}
	public static void saveSharedPref(Context activity,String key,String value) {
        SharedPreferences.Editor editor = activity.getSharedPreferences("data",Activity.MODE_PRIVATE).edit();
        editor.putString(key, value);
        editor.commit();
    }
	public static String getSharedPref(Context activity,String key){
	    SharedPreferences preferences = activity.getSharedPreferences("data", Activity.MODE_PRIVATE);
	    String value = preferences.getString(key, "");
	    return value;
	}
	
	  
    public static int dip2px(Context context, float dpValue) {  
        final float scale = context.getResources().getDisplayMetrics().density;  
        return (int) (dpValue * scale + 0.5f);  
    }  
  
      
    public static int px2dip(Context context, float pxValue) {  
        final float scale = context.getResources().getDisplayMetrics().density;  
        return (int) (pxValue / scale + 0.5f);  
    }  
}
